class Solution
{
public:
    int maximumEnergy(vector<int> &energy, int k)
    {
        int result = -1e9;
        int n = energy.size();
        for (int end = n - 1; end >= n - k; --end)
        {
            int sum = energy[end];
            result = max(result, sum);
            for (int i = end - k; i >= 0; i -= k)
            {
                sum += energy[i];
                result = max(result, sum);
            }
        }
        return result;
    }
};